<?php
Prado::using("Application.common.common");
class LeftColumn extends TTemplateControl
{
	public function onLoad($param)
	{
		parent::onLoad($param);
		if (!$this->Page->IsPostBack)
		{
			$this->getExclusiveProduct();
			$this->getLatestProduct();
			$this->getPromotionProduct();
			$this->populateTestimonial();
		}
	}
	
	public function getExclusiveProduct($id=0)
	{
		$criteria = new TActiveRecordCriteria;
		$criteria->Condition = "product_id = (select max(p.product_id) from tbl_product p where p.product_id > 0 and p.product_publish = 1 and p.product_hot_deal = 1)";
		$items = ProductRecord::finder()->findAll($criteria);
		foreach ($items as $activeRecord) 
		{
			if ($activeRecord->ImageHotDealPath != "")
				$this->imgExclusiveProductPhotoThumb->ImageUrl = $this->Request->UrlManagerModule->UrlPrefix."/useruploads/images/product/thumbs/".$activeRecord->ImageHotDealPath;
			else
				$this->imgExclusiveProductPhotoThumb->ImageUrl = $this->Request->UrlManagerModule->UrlPrefix."/useruploads/images/product/thumbs/".$activeRecord->ThumbnailPath;
			$this->imgExclusiveProductPhotoThumb->NavigateUrl = $this->Service->ConstructUrl('shop.ProductDetails',array('id'=>$activeRecord->ID,'alias'=>$activeRecord->Alias));	
			$this->lblExclusiveProductPrice->Text = Common::getFormattedValue($activeRecord->Price);
			$this->lnkExclusiveProductDetails->NavigateUrl = $this->Service->ConstructUrl('shop.ProductDetails',array('id'=>$activeRecord->ID,'alias'=>$activeRecord->Alias));
		}
		
	}
	
	public function getLatestProduct($is=0)
	{
		$criteria = new TActiveRecordCriteria;
		$criteria->Condition = "product_id = (select max(p.product_id) from tbl_product p where p.product_id > 0 and p.product_publish = 1 and p.product_new_arrival = 1)";
		$items = ProductRecord::finder()->findAll($criteria);
		foreach ($items as $activeRecord) 
		{				
			if ($activeRecord->ImageNewArrivalPath != "")
				$this->imgLatestProductPhotoThumb->ImageUrl = $this->Request->UrlManagerModule->UrlPrefix."/useruploads/images/product/thumbs/".$activeRecord->ImageNewArrivalPath;
			else
				$this->imgLatestProductPhotoThumb->ImageUrl = $this->Request->UrlManagerModule->UrlPrefix."/useruploads/images/product/thumbs/".$activeRecord->ThumbnailPath;
			$this->imgLatestProductPhotoThumb->NavigateUrl = $this->Service->ConstructUrl('shop.ProductDetails',array('id'=>$activeRecord->ID,'alias'=>$activeRecord->Alias));
			$this->lblLatestProductPrice->Text = Common::getFormattedValue($activeRecord->Price);
			$this->lnkLatestProductDetails->NavigateUrl = $this->Service->ConstructUrl('shop.ProductDetails',array('id'=>$activeRecord->ID,'alias'=>$activeRecord->Alias));
		}
		
	}
	
	public function getPromotionProduct($id=0)
	{
		$criteria = new TActiveRecordCriteria;
		$criteria->Condition = "product_id = (select max(p.product_id) from tbl_product p where p.product_id > 0 and p.product_publish = 1 and p.product_best_seller = 1)";
		$items = ProductRecord::finder()->findAll($criteria);
		foreach ($items as $activeRecord) 
		{
			if ($activeRecord->ImageHotDealPath != "")
				$this->imgPromotionProductPhotoThumb->ImageUrl = $this->Request->UrlManagerModule->UrlPrefix."/useruploads/images/product/thumbs/".$activeRecord->ImageBestSellerPath;
			else
				$this->imgPromotionProductPhotoThumb->ImageUrl = $this->Request->UrlManagerModule->UrlPrefix."/useruploads/images/product/thumbs/".$activeRecord->ThumbnailPath;
			$this->imgPromotionProductPhotoThumb->NavigateUrl = $this->Service->ConstructUrl('shop.ProductDetails',array('id'=>$activeRecord->ID,'alias'=>$activeRecord->Alias));	
			$this->lblPromotionProductPrice->Text = Common::getFormattedValue($activeRecord->Price);
			$this->lnkPromotionProductDetails->NavigateUrl = $this->Service->ConstructUrl('shop.ProductDetails',array('id'=>$activeRecord->ID,'alias'=>$activeRecord->Alias));
		}		
	}
	
	public function populateTestimonial()
	{
        $sqlmap = $this->Application->Modules['sqlmap']->Client;
		$sql = null;
		$limit = 4;
		$offset = null;
		$order = "testimonial_id desc";
		$items = $sqlmap->queryForList("BrowseTestimonial", array("ADDITIONAL_CONDITION"=>$sql,"ORDER_BY"=>$order),null,$offset,$limit);
		$this->TestimonialList->DataSource = $items;
		$this->TestimonialList->DataBind();
		if (count($items) <= 0)
		{
		}
	}
}

?>